﻿@model GameSchool.Models.ViewModels.TeacherViewModels.EditTestViewModel
@{
    ViewBag.Title = "Edit Test";
}

<h2>Edit: @Model.Test.Name (@Model.Test.Points)</h2>
<p id="TestDesc">@Model.Test.Description</p>
@foreach (var question in Model.Questions)
{
    <h3>@question.Question (@question.Points)</h3>
    foreach (var answer in Model.Answers)
    {
        <ul>
        @if (answer.QuestionID == question.ID)
        {
            <li>@answer.Answer
            @if(answer.Correct == true)
            {
                <i class="icon-ok"></i>
            }
            </li>
        }
        </ul>
    }
}

<div id="new_question_position">
    <p><br /><a id="newQuestion" onclick="addQuestionTempl()">Búa til nýja spurningu</a></p>
</div>

<script type="text/html" id="new_question_template">
@using (Html.BeginForm("EditTest", "Teacher", IsPost)) {
    @Html.ValidationSummary(true)

    <div class="editor-label">
        @Html.LabelFor(model => model.newQuestion.Question, "Spurning")
    </div>
    <div class="editor-field">
        @Html.TextAreaFor(model => model.newQuestion.Question)
        @Html.ValidationMessageFor(model => model.newQuestion.Question)
    </div>
    
    <div class="editor-label">
        @Html.LabelFor(model => model.newQuestion.Points, "Stigagildi Spurningar")
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(model => model.newQuestion.Points)
        @Html.ValidationMessageFor(model => model.newQuestion.Points)
    </div>

    @Html.HiddenFor(model => model.Test.ID)

    for ( int i = 0; i < 4; i++)
    {
        <div class="editor-label">
            Svarmöguleiki
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.newAnswers[i].Answer)
            @Html.ValidationMessageFor(model => model.newAnswers[i].Answer)
        </div>
    }
    
    <input class="SaveChanges" type="submit" value="Búa til spurningu" />
}
</script>

<script type="text/javascript">
    function addQuestionTempl() {
        $("#new_question_template").tmpl().appendTo("#new_question_position");
        $("#newQuestion").remove();
    }
</script>


<!-- Þessi kóði á að gefa kennaranum möguleikann á að ráða hversu margar spurningar eru í prófi.
    Vantar að geta tekið inn hvaða fjölda sem er af svörum fyrir spurningar

<script type="text/html" id="new_question_link_template">
    <p><a id="newQuestion" href=""></a>Búa til nýja spurningu</p>
</script>

<script type="text/html" id="add_answer_template">
    <label for="answer_text"></label>
    <li><textarea class="answer_text" name="answer_text" rows="1" cols="30" autofocus="autofocus"></textarea>
    <input type="radio" name="answer">Rétt svar<br/></li>
</script>

<script type="text/javascript">
    function addQuestionTempl() {
        $("#new_question_template").tmpl().appendTo("#new_question_position");
        $("#newQuestion").remove();
    }

    function addAnswerTemplate() {
        $("#add_answer_template").tmpl().insertBefore("#herpDerp");
    }
</script>
-->